from django.shortcuts import render, redirect
from component_1.models import *


# Create your views here.
def Show_Homepage(request):
    """
    显示的主页面
    """
    return render(request, 'show.html', {})


def Delete_Data(request):
    """
    删除数据
    """
    return render(request, '', {})


def Modify_Data(request):
    """
    修改数据
    """
    return render(request, '', {})


def Ddd_Data(request):
    """
    添加学生的数据
    """
    if request.method == 'GET':
        data = Teacher.objects.all()
        return render(request, 'add_data.html', {'data': data})
    if request.method == 'POST':
        name = request.POST.get('name')
        sex = request.POST.get('sex')
        Date_of_birth = request.POST.get('Date_of_birth')
        contact = request.POST.get('contact')
        class_n = request.POST.get('class_n')
        The_connection = request.POST.get('The_connection')
        sq = Students(name=name, sex=sex, Date_of_birth=Date_of_birth, contact=contact, class_n=class_n,
                      The_connection_id=The_connection)
        sq.save()
        return redirect('Show_Homepage')


def Ddd_Data_Teacher(request):
    """
    添加老师的数据
    """
    if request.method == 'GET': 
        data = Teacher.objects.all()
        # print(data)
        # print(type(data))
        return render(request, 'add_teacher.html', {'data': data})
    if request.method == 'POST':
        name = request.POST.get('name')
        sex = request.POST.get('sex')
        Date_of_birth = request.POST.get('Date_of_birth')
        contact = request.POST.get('contact')
        call = request.POST.get('call')
        sq = Teacher(name=name, sex=sex, Date_of_birth=Date_of_birth, contact=contact, call=call)
        sq.save()
        return redirect('Show_Homepage')


def Query_Data(request):
    """
    查询
    """
    return render(request, '', {})
